
const namespace = 'perspectiveOrgModel';
const loginAction = /\/login/gi;
export default {
    namespace,
    state: {
        selectOrganizationCode: ''
    },
    reducers: {
        setOrg(state, action) {
            return {
                ...action.payload
            };
        },
        clear() {
            return {
                selectOrganizationCode: ''
            };
        }
    },

    subscriptions: {
        setup(props) {
            const { dispatch, history } = props;
            return history.listen(({ pathname }) => {
                if (String(pathname).search(loginAction) > -1) { // 如果是登录登出操作清空缓存
                    dispatch({
                        type: 'clear'
                    });
                }
            });
        }
    }
};
